package com.dc.chat.controller;

import com.dc.chat.app.service.FileService;
import com.dc.chat.entity.dao.FileMessage;
import com.dc.chat.entity.to.ResponseBean;
import com.dc.chat.interceptor.security.Security;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletResponse;
import java.io.File;
import java.io.IOException;

@RestController
@RequestMapping("/file")
public class FileController {
    @Resource
    FileService fileService;
    @Security
    @PostMapping("/upload")
    public ResponseBean<String> upload(@RequestParam("file") MultipartFile multipartFile) throws IOException {
        return fileService.upload(multipartFile);
    }
    @RequestMapping("/{uuid}")
    public void downLoad(@PathVariable("uuid")String fileName, HttpServletResponse resp) throws IOException {
        fileService.downLoad(fileName, resp);
    }
}
